package com.woniu.microassetserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.microassetserver.mapper.AssetsParameterMapper;
import com.woniu.microassetserver.service.AssetsParameterService;
import com.woniu.microcommonsserver.entity.AssetsParameterEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Transactional(readOnly = true)
@Service
public class AssetsParameterServiceImpl implements AssetsParameterService {

    @Resource
    private AssetsParameterMapper assetsParameterMapper;


    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int saveAssetsParameter(AssetsParameterEntity assetsParameterEntity) {
        return assetsParameterMapper.saveAssetsParameter(assetsParameterEntity);
    }

    @Override
    public AssetsParameterEntity getOneById(Long id) {
        return assetsParameterMapper.getOneById(id);
    }

    @Override
    public PageInfo<AssetsParameterEntity> findAllByParams(int pageNum, int pageSize, AssetsParameterEntity assetsParameterEntity) {
        return PageHelper.startPage(pageNum,pageSize).
                doSelectPageInfo(()->assetsParameterMapper.findAllByParams(assetsParameterEntity));
    }


    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateAssetsParameter(AssetsParameterEntity assetsParameterEntity) {
        return assetsParameterMapper.updateAssetsParameter(assetsParameterEntity);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deleteAssetsParameter(Integer id) {
        return assetsParameterMapper.deleteAssetsParameter(id);
    }
}